package com.ruoyi.web.core.config;

import com.github.alenfive.rocketapi.extend.IResultWrapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class RocketResultWrapperConfig implements IResultWrapper {
    @Override
    public Object wrapper(Object data, HttpServletRequest request, HttpServletResponse response) {
        return new ResultWrapper(200,request.getRequestURI(),"操作成功",data);

    }

    @Override
    public Object throwable(Throwable throwable, HttpServletRequest request, HttpServletResponse response) {
        return new ResultWrapper(500,request.getRequestURI(),throwable.getMessage(),null);
    }


    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ResultWrapper {
        private Integer code;
        private String action;
        private String msg;
        private Object data;
    }
}
